﻿@model Resto.CostControl.Core.DishDelivery
@{
    ViewBag.Title = "发货单维护";
    Layout = "~/Views/Shared/_LayoutForm.cshtml"; 
}
@using (Html.AjaxBeginForm("Save"))
{ 
    <!-- 主表 --> 
    <div class="pageFormContent" style="width: 600px">
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.State)
        @Html.DWZDropDownListFor(model => model.SiteID, "ProjectSite").Required()
        @Html.DWZDateFor(model => model.Date).Required()
    </div>
    <div class="clear">
    </div>
    <!-- 子表 --> 
    <div class="pageFormDetailList">
        @Html.Css("flexigrid", "tmpl", "list")
        @Html.Js("flexigrid", "tmpl", "list")
        @(        
 Html.DWZGridFor<Resto.CostControl.Core.MaterialPurchaseItem>()
        .Title("品名列表")
        .ID("MaterialList")
        .Action(@Url.Action("EditList"))
        .ExtParam(new { ParentId = "$('#Id').val()" })
        .Width(580)
        .Height(130)
        .Columns(col =>
        {
            col.Bind(e => e.Id).IsKey().Sortable(false);
            col.Bind(e => e.Code).Width(60).Align(FlexiGridAlign.Left).Sortable(false);
            col.Bind(e => e.Name).Width(60).Align(FlexiGridAlign.Left).Sortable(false);
            col.Bind(e => e.Price).Width(60).Align(FlexiGridAlign.Right).Sortable(false);
            col.Bind(e => e.OrderCount).Template(@Html.TextBox("OrderCount", "${OrderCount}", new { style = "text-align:right;width:56px" }).ToString()).Width(79).Sortable(false);
            col.Bind(e => e.DeliveryCount).Width(60).Align(FlexiGridAlign.Right).Sortable(false);
            col.Bind(e => e.Category).EnumKey("DishType").Width(60).Align(FlexiGridAlign.Right).Sortable(false);
            col.Bind(e => e.StorageCount).Width(60).Align(FlexiGridAlign.Right).Sortable(false);
        })
        .ShowCheckBox(false)
        .UsePager(false)
        //.Buttons(btn =>
        //{
        //    btn.Bind("Add", "选择品名", FlexiGridButtonType.Add).OnPress("SelectMaterial");
        //})
    )
    </div>
}
@Html.FormBar()
<script type="text/javascript">
    function Additem() {
        var id = $("#Id").val();
        OpenModalDialog('@Url.Action("EditItem")?ParentId=' + id, { width: 480, height: 300, onclose: ReLoadMaterialList });
    }

    function SelectMaterial(e) {
        OpenModelWindow('@Url.Action("LookUp", "Dish")', { caption: "选择品名", width: 840, height: 400, onclose: function (MaterialData) {
            if (MaterialData) {
                $("#MaterialList").flexAddRows(MaterialData);
            }
        }
        });
    }

    function ReLoadMaterialList() {
        $("#MaterialList").flexReload();
    }

    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("MaterialList")',
            data: { "SiteId": "", "ReportDate": $("#OrderDate").val() },
            dataType: "json",
            success: function (orderlist) {
                $("#MaterialList").flexAddRows(orderlist);
            }
        });      //end if $.ajax
    });
</script>
